package cn.edu.zxj.ojspring.controller;

import cn.edu.zxj.ojspring.model.Result;
import cn.edu.zxj.ojspring.model.info.OJInfo;
import cn.edu.zxj.ojspring.service.OJService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description：
 *
 * @author: zxj
 * @date: 2024-02-21
 * @time: 17:02:26
 */
@RestController
@RequestMapping("/oj")
@Slf4j
public class OJController {

    @Autowired
    private OJService ojService;

    @RequestMapping("/getProblem")
    public List<OJInfo> getProblem() {
        log.info("接收到获取所有题目信息请求...");

        return ojService.getProblem();
    }

    @RequestMapping("/getProblemDetail")
    public Result getProblemDetail(Integer id) {
        log.info("接收到获取题目{} 详细信息请求...", id);

        // 参数校验
        if (id == null || id < 1) {
            return Result.fail("参数传入错误~");
        }

        OJInfo ojInfo = ojService.getProblemDetail(id);

        if (ojInfo == null) {
            return Result.fail("内部出现错误, 请联系管理员~");
        }

        return Result.success(ojInfo);

    }


}
